package util

func Union[T comparable](sets ...Set[T]) Set[T] {
	result := NewSet[T]()

	for _, set := range sets {
		result.Add(set.ToSlice()...)
	}

	return result
}
func Intersect[T comparable](sets ...Set[T]) Set[T] {
	records := map[T]int{}

	for _, set := range sets {
		for _, element := range set.ToSlice() {
			records[element] = records[element] + 1
		}
	}

	result := NewSet[T]()

	for element, num := range records {
		if num == len(sets) {
			result.Add(element)
		}
	}

	return result
}
func Difference[T comparable](left, right Set[T]) Set[T] {
	result := left.Clone()

	result.Remove(right.ToSlice()...)

	return result
}
